﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AppManagement.Models;

namespace AppManagement.Reports
{
    public partial class FrmInHoaDonThanhToan : Form
    {
        private List<PhieuKham_DichVu> _lstPhieuThu;
        private PhieuKham _phieukham;

        public FrmInHoaDonThanhToan(List<PhieuKham_DichVu> lstItem, PhieuKham pk)
        {
            InitializeComponent();
            _lstPhieuThu = lstItem;
            _phieukham = pk;
        }

        public void LoadData()
        {
            long tongtien = 0;
            var dt = new DataTable();
            dt.Columns.Add("STT");
            dt.Columns.Add("TenDichVu");
            dt.Columns.Add("DonGia");

            for (int i = 0; i < _lstPhieuThu.Count; i++)
            {
                dt.Rows.Add((i + 1).ToString(), _lstPhieuThu[i].DichVu.TenDV, String.Format("{0:#,##0;Nothing}", _lstPhieuThu[i].DichVu.PhiDV));
                tongtien += _lstPhieuThu[i].DichVu.PhiDV.Value;
            }

            rptHoaDonThanhToan rpt = new rptHoaDonThanhToan();
            rpt.DataDefinition.FormulaFields["HoTen"].Text = "'" + _phieukham.BenhNhan.ToString() + "'";
            rpt.DataDefinition.FormulaFields["NgaySinh"].Text = "'" + String.Format("{0:dd/MM/yyyy}", _phieukham.BenhNhan.NgaySinh) + "'";
            rpt.DataDefinition.FormulaFields["GioiTinh"].Text = "'" + (_phieukham.BenhNhan.GioiTinh.Value ? "Nam" : "N?") + "'";
            rpt.DataDefinition.FormulaFields["DiaChi"].Text = "'" + _phieukham.BenhNhan.DiaChi + "'";
            rpt.DataDefinition.FormulaFields["DienThoai"].Text = "'" + _phieukham.BenhNhan.DienThoai + "'";
            rpt.DataDefinition.FormulaFields["NgheNghiep"].Text = "'" + _phieukham.BenhNhan.NgheNghiep + "'";
            rpt.DataDefinition.FormulaFields["NgayKham"].Text = "'" + String.Format("{0:dd/MM/yyyy}", _phieukham.NgayKham) + "'";
            rpt.DataDefinition.FormulaFields["TinhTrang"].Text = "'" + _phieukham.BenhNhan.TinhTrangToiKham + "'";
            rpt.DataDefinition.FormulaFields["TongTien"].Text = "'" + String.Format("{0:#,##0;Nothing}", tongtien) + "'";

            rpt.SetDataSource(dt);
            crystalReportViewer1.ReportSource = rpt;
        }

        private void FrmInHoaDonThanhToan_Load(object sender, EventArgs e)
        {
            LoadData();
        }
    }
}
